package com.dao.impl;

import com.dao.BaseDao;
import com.dao.MsgUserInfoDao;
import com.entity.MsgUserInfo;

import java.util.List;

public class MsgUserInfoDaoImpl extends BaseDao implements MsgUserInfoDao {
    @Override
    public MsgUserInfo login(String name, String pwd) {
        String sql = "select * from msg_userinfo where username = ? and password = ?";
        Object[] obj = {name,pwd};
        List<MsgUserInfo> list = (List<MsgUserInfo>) query(sql, obj, MsgUserInfo.class);
        return list!= null && list.size() > 0 ? list.get(0):null;
    }

    @Override
    public MsgUserInfo findByName(String name) {
        String sql = "select * from msg_userinfo where username = ? ";
        Object[] obj = {name};
        List<MsgUserInfo> list = (List<MsgUserInfo>) query(sql, obj, MsgUserInfo.class);
        return list!= null && list.size() > 0 ? list.get(0):null;
    }

    @Override
    public int addUser(MsgUserInfo user) {
        String sql = "insert into msg_userinfo values(?,?,?)";
        Object[] obj = {user.getUsername(), user.getPassword(), user.getEmail()};
        return saveOrUpdateORDel(sql, obj);
    }
}
